package exchange;

import main.Chat;

import org.bukkit.inventory.ItemStack;

public class Item {
	private final String name;
	private final ItemStack itemstack;
	private int quantity = 0;
	private double price = 0;

	public Item(String name, ItemStack itemstack) {
		this.name = name;
		this.itemstack = itemstack;
	}
	
	public Item(String name, ItemStack itemstack, int quantity) {
		this(name, itemstack);
		this.quantity = quantity;
	}
	
	public Item(String name, ItemStack itemstack, int quantity, int price) {
		this(name, itemstack, quantity);
		this.price = price;
	}
	
	public String getName() {
		return name;
	}
	
	public ItemStack getItemStack() {
		return itemstack;
	}
	
	public ItemStack getItemStack(int amount) {
		ItemStack desiredStack = getItemStack();
		desiredStack.setAmount(amount);
		return desiredStack;
	}
	
	public int getQuantity() {
		return quantity;
	}
	
	public boolean increaseQuantity(int amount) {
		if (amount >= 0) {
			quantity = quantity + amount;
			return true;
		}
		return false;
	}
	
	public boolean decreaseQuantity(int amount) {
		if (amount >= 0 && quantity - amount >= 0) {
			quantity = quantity - amount;
			return true;
		}
		return false;
	}
	
	public boolean setQuantity(int quantity) {
		if (quantity >= 0) {
			this.quantity = quantity;
			return true;
		}
		return false;
	}
	
	public double getPrice() {
		return price;
	}
	
	public boolean setPrice(double price) {
		if (price >= 0) {
			this.price = price;
			return true;
		}
		return false;
	}
	
	@Override
	public String toString() {
		return Chat.YELLOW + name + Chat.WHITE + " : " 
				+ Chat.RED + price + Chat.WHITE + " : "
				+ Chat.GREEN + quantity;
	}
}
